using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ChooseWindow : MonoBehaviour
{
    public List<ChoosedPawn> choosedPawns = new List<ChoosedPawn>();

    /// <summary>
    /// Awake is called when the script instance is being loaded.
    /// </summary>
    void Awake()
    {
        foreach (var c in choosedPawns)
        {
            c.window = this;
        }
    }

    public void ShowWaitChooseWindow(List<Pawn> prefabs)
    {
        gameObject.SetActive(true);
        int i = 0;
        for (; i < prefabs.Count; i++)
        {
            var prefab = prefabs[i];
            choosedPawns[i].SetPawn(prefab);
            choosedPawns[i].gameObject.SetActive(true);
        }

        for (; i < choosedPawns.Count; i++)
        {
            choosedPawns[i].gameObject.SetActive(false);
        }
    }

    public void OnSelectPawn(ChoosedPawn choosed)
    {
        foreach (var c in choosedPawns)
        {
            if (choosed != c)
            {
                c.ShowFrame(false);
            }
            else
            {
                c.ShowFrame(true);
            }
        }
        CardManager.instance.SelectedPawn = choosed.Pawn;
    }

    public void OnFinishChooseButton()
    {
        gameObject.SetActive(false);
        Reset();
        CardManager.instance.FinishChoose();
    }

    public void OnSkipChooseButton()
    {
        gameObject.SetActive(false);
        Reset();
        CardManager.instance.SkipChoose();
    }

    public void Reset()
    {
        foreach (var c in choosedPawns)
        {
            c.Reset();
        }
    }
}
